﻿namespace Web.Control.WWW.Group
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;

    /// <summary>
    /// EditGroup 的摘要说明
    /// </summary>
    public class MyGroups : BaseControl
    {
        /// <summary>
        /// 当前会员编号
        /// </summary>
        protected string Memberno = "";
        /// <summary>
        /// 绑定组数据
        /// </summary>
        protected Repeater gList;        
        /// <summary>
        /// 绑定讨论数据
        /// </summary>
        protected Repeater rptTopic;
        /// <summary>
        /// 数据数量
        /// </summary>
        protected int RecordCount = 0;
        protected int PageIndex = 1;
        protected Literal litCount;

        protected string C0087 = "";
        protected string C0105 = "";
        protected string C2018 = "";
        protected string GP006 = "";
        protected string GP008 = "";
        protected string GP012 = "";
        protected string GP013 = "";
        protected string GP014 = "";
        protected string GP016 = "";
        protected string GP206 = "";
        protected string GP041 = "";
        protected override void OnLoad(EventArgs e)
        {
            Memberno = HttpContext.Current.User.Identity.Name;
            if (Memberno == "")
            {
                Response.Redirect(LoginHost + "/User/login.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri.Split('?')[0]);
                return;
            }
            int psize = 15;
            if (litCount != null) int.TryParse(litCount.Text, out psize);
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["page"] == "L")
                {
                    PageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out PageIndex);
                    if (PageIndex == 0)
                    {
                        PageIndex = 1;
                    }
                }
            }
            ArrayList arrList;
            if (!string.IsNullOrEmpty(Request.Form["LeaveGID"]))
            {
                arrList = BLF.WWW_WWW.Group.Group.GetMyGroupsOP(Memberno, PageIndex, psize, Request.Form["LeaveGID"]);
            }
            else
            {
                arrList = BLF.WWW_WWW.Group.Group.GetMyGroups(Memberno, PageIndex, psize);
            }
            if (arrList != null && arrList.Count > 1)
            {
                C0087 = GetText("C0087");
                C0105 = GetText("C0105");
                C2018 = GetText("C2018");
                GP006 = GetText("GP006");
                GP008 = GetText("GP008");
                GP012 = GetText("GP012");
                GP013 = GetText("GP013");
                GP014 = GetText("GP014");
                GP016 = GetText("GP016");
                GP206 = GetText("GP206");
                GP041 = GetText("GP041");

                RecordCount = (int)arrList[1];
                int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)psize));
                if (PageIndex > pCount) PageIndex = pCount;

                if (gList != null)
                {
                    gList.DataSource = arrList[0];
                    gList.DataBind();
                }                
                if (rptTopic != null)
                {
                    rptTopic.DataSource = arrList[2];
                    rptTopic.DataBind();
                }
            }
            else
            {
                Response.End();
            }
            base.OnLoad(e);
        }
    }
}
